package com.trg.flex.frm.validation
{
	import mx.validators.DateValidator;
	import mx.validators.ValidationResult;

	public class ExtDateValidator extends DateValidator
	{
		public function ExtDateValidator()
		{
			super();
		}
		
		public var past:Boolean = false;
		public var future:Boolean = false;
		
		override protected function doValidation(value:Object):Array {
			var results:Array = super.doValidation(value);
			
			if (results.length == 0 && (past || future)) {
				if (value is String) value = new Date(value);
				var today:Date = new Date();
				today.setHours(0,0,0,0);
				if (past) {
					today.setDate(today.getDate() + 1);
					if (value >= today) {
						results.push(new ValidationResult(
							true, null, "notPast",
							"The date is invalid. It must be in the past."));
					}
				} else if (future) {
					if (value < today) {
						results.push(new ValidationResult(
							true, null, "notFuture",
							"The date is invalid. It must be in the future."));
					}
				}
			}
				
			return results;
		}
	}
}